import * as React from "react"
import { type SearchParams } from "@/types/table"
import { getValidFilters } from "@/lib/data-table"
import { Skeleton } from "@/components/ui/skeleton"
import { DataTableSkeleton } from "@/components/data-table/data-table-skeleton"
import { Shell } from "@/components/shell"
import { getBasicContractsByVendorId } from "@/lib/basic-contract/service"
import { searchParamsVendorCache } from "@/lib/basic-contract/validations"
import { redirect } from "next/navigation"
import { BasicContractsVendorTable } from "@/lib/basic-contract/vendor-table/basic-contract-table"
import { getServerSession } from "next-auth"
import { authOptions } from "@/app/api/auth/[...nextauth]/route"
import { InformationButton } from "@/components/information/information-button"
import { useTranslation } from "@/i18n"
interface IndexPageProps {
  params: Promise<{ lng: string }>
  searchParams: Promise<SearchParams>
}

export default async function IndexPage(props: IndexPageProps) {
  const { lng } = await props.params;
  const { t } = await useTranslation(lng, 'menu')
  const session = await getServerSession(authOptions)
  const vendorId = session?.user.companyId  

  const searchParams = await props.searchParams
  const search = searchParamsVendorCache.parse(searchParams)

  const validFilters = getValidFilters(search.filters)

  const promises = Promise.all([
    getBasicContractsByVendorId(
      {
        ...search,
        filters: validFilters,
      },
      Number(vendorId)
    ),
  ])

  return (
    <Shell className="gap-2">
      <div className="flex items-center justify-between space-y-2">
        <div className="flex items-center justify-between space-y-2">
          <div>
            <div className="flex items-center gap-2"> 
              <h2 className="text-2xl font-bold tracking-tight">
                {t('menu.vendor.procurement.basic_contract_sign')}
              </h2>
              <InformationButton pagePath="partners/basic-contract" />
            </div>
            {/* <p className="text-muted-foreground">
              기본계약서를 비롯하여 초기 서명이 필요한 문서의 서명 현황을 확인할 수 있고 서명을 진행할 수 있습니다. {" "}
            </p> */}
          </div>
        </div>
      </div>

      <React.Suspense fallback={<Skeleton className="h-7 w-52" />}>
        {/* <DateRangePicker
            triggerSize="sm"
            triggerClassName="ml-auto w-56 sm:w-60"
            align="end"
            shallow={false}
          /> */}
      </React.Suspense>
      <React.Suspense
        fallback={
          <DataTableSkeleton
            columnCount={6}
            searchableColumnCount={1}
            filterableColumnCount={2}
            cellWidths={["10rem", "40rem", "12rem", "12rem", "8rem", "8rem"]}
            shrinkZero
          />
        }
      >
        <BasicContractsVendorTable promises={promises} />
      </React.Suspense>
    </Shell>
  )
}
